classdef Gas < handle
    %GAS Summary of this class goes here
    %   Detailed explanation goes here

    properties
        name
        atom
        type
        density
        pressure
        temperature
        velocity_doppler
        transition
        subspace

        gamma2 = 0
    end

    methods
        function obj = Gas(atom, type, varargin)
            p = inputParser;

            isnonneg = @(x) isnumeric(x) && x > 0;
            atomCheck = @(x) isa(x, 'Atom.Atom');
            typeCheck = @(x) any(ismember({'vapor', 'buffer', 'noble'}, x));
            transCheck = @(x) ischar(x) || isa(x, 'Atom.Transition');
            subspaceCheck = @(x) any(ismember({'vacuum', 'vacuum-ground', 'vacuum-full', 'vacuum-ground-rate'}, x));

            p.addRequired('atom', atomCheck);
            p.addRequired('type', typeCheck);
            p.addParameter('temperature', 300.0,     isnonneg);         % [Kelvin]
            p.addParameter('pressure',    1e5,       isnonneg);         % [Pasca]
            p.addParameter('transition',  '',        transCheck);
            p.addParameter('subspace',    'vacuum',  subspaceCheck);
            p.addParameter('name',        '',        @ischar);

            p.parse(atom, type, varargin{:});
            parameters = p.Results;

            obj.atom = parameters.atom;
            obj.type = parameters.type;
            obj.temperature = parameters.temperature;
            obj.name = parameters.name;

            if strcmp(parameters.type, 'vapor')
                obj.pressure = obj.getPressure(parameters.temperature);
            else
                obj.pressure = parameters.pressure;
            end

            obj.transition = parameters.transition;
            obj.subspace = parameters.subspace;
            obj.density = parameters.pressure / kB / parameters.temperature ...
                         * atom.parameters.abundance;

            obj.velocity_doppler = obj.dopplerBroadening();
        end

        function obj = set_temperature(obj, temperature)
            if strcmp(obj.type, 'vapor')
                obj.pressure = obj.getPressure(temperature);
                obj.density = obj.pressure / kB / temperature * obj.atom.parameters.abundance;
                mass = Atom.AtomParameters(obj.atom.name).mass / avogadro * 1e-3;
                obj.velocity_doppler = sqrt( kB*temperature / mass );
            end
        end

    end

end
